﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Server
{
    public class CProduct
    {
        private int _ma;
        private string _ten;
        private double _giatien;
        private DateTime _ngaydang;
        private string _mota;
        private int _soluongbanduoc;
        private double _doanhthu;

        public double Doanhthu
        {
            get { return _doanhthu; }
            set { _doanhthu = value; }
        }
        public int Soluongbanduoc
        {
            get { return _soluongbanduoc; }
            set { _soluongbanduoc = value; }
        }

        public CProduct()
        {
            _ngaydang = DateTime.Now;
        }

        public CProduct(System.Xml.XmlNodeList childnode)
        {
            try
            {
                _ma = int.Parse(childnode.Item(0).InnerText.Trim());
                _ten = childnode.Item(1).InnerText.Trim();
                _giatien = double.Parse(childnode.Item(2).InnerText.Trim());
                _mota = childnode.Item(3).InnerText.Trim();
                if (!DateTime.TryParse(CDateTime.DateTimeParse(childnode.Item(4).InnerText.Trim()).ToString(), out _ngaydang))
                {
                    childnode.Item(4).InnerText = DateTime.Now.ToShortDateString();
                }
                
            }
            catch(Exception c)
            {
                throw new Exception("Định dạng CSDL không đúng");
            }
        }

        public int Ma
        {
            get { return _ma; }
            set { _ma = value; }
        }
        public string Ten
        {
            get { return _ten; }
            set { _ten = value; }
        }
        public double Giatien
        {
            get { return _giatien; }
            set { _giatien = value; }
        }
        
        public DateTime Ngaydang
        {
            get { return _ngaydang; }
            set { _ngaydang = value; }
        }
        public string Mota
        {
            get { return _mota; }
            set { _mota = value; }
        }

        override public string ToString()
        {
            string str = String.Empty;
            str = String.Concat(str, "Ma = ", Ma, "\r\n");
            str = String.Concat(str, "Ten = ", Ten, "\r\n");
            str = String.Concat(str, "Giatien = ", Giatien, "\r\n");
            str = String.Concat(str, "Ngaydang = ", Ngaydang, "\r\n");
            str = String.Concat(str, "Mota = ", Mota, "\r\n");
            return str;
        }
    }
}
